#include <iostream>
using namespace std;

//打印数组
void printArray(int array[], int n)
{
	for (int i = 0; i < n; i++)
	{
		cout << array[i]<<" ";
	}
	cout << endl;
}

//定义插入排序函数
int insertion(int array[], int n,int k)
{
	for (int i = 0; i < n; i++)
	{
		int j = i - 1;
		int temp = array[i];
		for (; j >= 0; j--)
		{
			if (array[j] >= temp)
			{
				array[j + 1] = array[j];
			}
			else
				break;
		}
		array[j + 1] = temp;
	}
	return array[n-k];
}


int main()
{
	int array1[] = {5,2,7,5,3,88,6,33,22};
	int n = sizeof(array1) / sizeof(int);
	int k = 0;
	cout << "What size do you want?" << endl;
	cin >> k;
	cout << "The anwser is:" << insertion(array1, n, k) << endl;
	printArray(array1, n);//打印排好序后的数组
}